/*
 * Copyright (c) 2010 Andy Aspell-Clark
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package uk.org.aspellclark.agenedb.view;

import uk.org.aspellclark.agenedb.R;
import uk.org.aspellclark.gedcom.controller.Db4oController;
import uk.org.aspellclark.gedcom.controller.HeaderController;
import uk.org.aspellclark.gedcom.model.records.Header;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class GedcomFileInformationView extends Activity {

	static TextView sourSysId;
	static TextView sourName;
	static TextView sourCorpName;
	static TextView sourCorpAddr;
	static TextView sourData;
	static TextView sourDataDate;
	static TextView sourDataCopyright;
	static TextView sourDestName;
	static TextView sourDateTime;
	static TextView sourSubm;
	static TextView sourSubn;
	static TextView sourFile;
	static TextView sourCopyright;
	static TextView sourGedcVers;
	static TextView sourGedcForm;
	static TextView sourChar;
	static TextView sourCharVers;
	static TextView sourLang;
	static TextView sourPlac;
	static TextView sourPlacForm;
	static TextView sourNote;

	static TextView nbrIndividualsVw;
	static TextView nbrFamiliesVw;

	private HeaderController headerCntrlr;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.gedcom_file_details);
		this.updateDetails();
	}

	private void updateDetails() {
		this.headerCntrlr = new HeaderController(Db4oController.getInstance());
		Header hdrRcrd = this.headerCntrlr.getHeader();
		if (hdrRcrd != null) {
			try {
				sourSysId = (TextView) this.findViewById(R.id.gedcomFileInfoSourceSystemId);
				sourSysId.setText("Source System Id: " + hdrRcrd.sour.id);

				sourName = (TextView) this.findViewById(R.id.gedcomFileInfoSourceNameOfProd);
				sourName.setText("Source System Name: " + hdrRcrd.sour.name);

				sourCorpName = (TextView) this.findViewById(R.id.gedcomFileInfoSourceCorpName);
				sourCorpName.setText("Corporation name: " + (hdrRcrd.sour.corpName != null ? hdrRcrd.sour.corpName : ""));

				sourCorpAddr = (TextView) this.findViewById(R.id.gedcomFileInfoSourceCorpAddress);
				sourCorpAddr.setText("Corporation address: "
						+ (hdrRcrd.sour.corpAddress != null ? hdrRcrd.sour.corpAddress : ""));

				sourData = (TextView) this.findViewById(R.id.gedcomFileInfoSourceData);
				sourData.setText("Name of Data: " + (hdrRcrd.sour.name != null ? hdrRcrd.sour.name : ""));

				sourDataDate = (TextView) this.findViewById(R.id.gedcomFileInfoSourceDataDate);
				sourDataDate.setText("Publication Date: " + (hdrRcrd.sour.dataDate != null ? hdrRcrd.sour.dataDate : ""));

				sourDataCopyright = (TextView) this.findViewById(R.id.gedcomFileInfoSourceDataCopr);
				sourDataCopyright.setText("Copyright: "
						+ (hdrRcrd.sour.dataCopyright != null ? hdrRcrd.sour.dataCopyright : ""));

				sourDestName = (TextView) this.findViewById(R.id.gedcomFileInfoSourceDataDate);
				sourDestName.setText("Destinaton system: " + (hdrRcrd.dest != null ? hdrRcrd.dest : ""));

				sourDateTime = (TextView) this.findViewById(R.id.gedcomFileInfoDateTime);
				sourDataDate.setText("Transmission date: " + (hdrRcrd.date != null ? hdrRcrd.date : ""));

				sourSubm = (TextView) this.findViewById(R.id.gedcomFileInfoSubm);
				sourSubm.setText("Submission: " + (hdrRcrd.submXRef != null ? hdrRcrd.submXRef : ""));

				sourSubn = (TextView) this.findViewById(R.id.gedcomFileInfoSubn);
				sourSubn.setText("Submitter: " + (hdrRcrd.subnXRef != null ? hdrRcrd.subnXRef : ""));

				sourFile = (TextView) this.findViewById(R.id.gedcomFileInfoFile);
				sourFile.setText("Filename: " + (hdrRcrd.fileName != null ? hdrRcrd.fileName : ""));

				sourCopyright = (TextView) this.findViewById(R.id.gedcomFileInfoCopyright);
				sourCopyright.setText("Copyright: " + (hdrRcrd.copyright != null ? hdrRcrd.copyright : ""));

				sourGedcVers = (TextView) this.findViewById(R.id.gedcomFileInfoGedCVersion);
				sourGedcVers.setText("Gedcom Version: " + (hdrRcrd.gedcVersion != null ? hdrRcrd.gedcVersion : ""));

				sourGedcForm = (TextView) this.findViewById(R.id.gedcomFileInfoGedCForm);
				sourGedcForm.setText("Gedcom Form: " + (hdrRcrd.gedcForm != null ? hdrRcrd.gedcForm : ""));

				sourChar = (TextView) this.findViewById(R.id.gedcomFileInfoCharSet);
				sourChar.setText("Character set: " + (hdrRcrd.charset != null ? hdrRcrd.charset : ""));

				sourCharVers = (TextView) this.findViewById(R.id.gedcomFileInfoCharVers);
				sourCharVers.setText("Char set version: " + (hdrRcrd.charsetVers != null ? hdrRcrd.charsetVers : ""));

				sourLang = (TextView) this.findViewById(R.id.gedcomFileInfoLang);
				sourLang.setText("Language: " + (hdrRcrd.language != null ? hdrRcrd.language : ""));

				sourPlac = (TextView) this.findViewById(R.id.gedcomFileInfoPlac);
				sourPlac.setText("Place: " + (hdrRcrd.placeHierarchy != null ? hdrRcrd.placeHierarchy : ""));

				sourNote = (TextView) this.findViewById(R.id.gedcomFileInfoNotes);
				sourNote.setText("Filename: " + hdrRcrd.note);

				nbrIndividualsVw = (TextView) this.findViewById(R.id.gedcomFileInfoNbrRecordsIndividual);
				nbrIndividualsVw.setText("X Individuals");

				nbrFamiliesVw = (TextView) this.findViewById(R.id.gedcomFileInfoNbrRecordsFamily);
				nbrFamiliesVw.setText("X Families");
			} catch (Exception e) {
				String errMsg = e.getMessage();
			}
		}
	}
}